#include "mainmenu.hpp"

namespace VN2{
	void StartButton::released(Window* w,SDL_FPoint& p){}
	StartButton::StartButton(TTF_Font* font):TextButton("开始",font){}
	void LoadButton::released(Window* w,SDL_FPoint& p){}
	LoadButton::LoadButton(TTF_Font* font):TextButton("读取",font){}
	void SettingButton::released(Window* w,SDL_FPoint& p){}
	SettingButton::SettingButton(TTF_Font* font):TextButton("设置",font){}
	void AboutButton::released(Window* w,SDL_FPoint& p){}
	AboutButton::AboutButton(TTF_Font* font):TextButton("关于",font){}
	void QuitButton::released(Window* w,SDL_FPoint& p){}
	QuitButton::QuitButton(TTF_Font* font):TextButton("退出",font){}

	OptionMenu::OptionMenu(TTF_Font* font):VBoxLayout({0,0,0,0},0.3f,0.3f,0.1f,0.1f,0.025f,{
		new StartButton(font),
		new LoadButton(font),
		new SettingButton(font),
		new AboutButton(font),
		new QuitButton(font)
	}){}

	MainMenuLayout::MainMenuLayout(SDL_Texture* back,SDL_Color menucover,
	float sep):back(back),sep(sep),cover(menucover){}
	MainMenuLayout::~MainMenuLayout(){}
	void MainMenuLayout::draw(SDL_Renderer* r,SDL_Texture* screen,bool updatecache){
		if(redraw|updatecache){
			redraw=false;
			notified=false;
			auto b=&rect;
			auto v=children[0];
			auto c=cover;
			auto& _=v->getrect();
			(SDL_FRect&)_={b->x,b->y,sep*b->w,b->h};
			v->forceredraw();
			SDL_RenderCopyF(r,back,nullptr,b);
			SDL_SetRenderDrawColor(r,c.r,c.g,c.b,c.a);
			SDL_RenderFillRectF(r,&_);
			v->draw(r,screen,true);
			return;
		}
		notified=false;
		auto v=children[0];
		if(v->confirmdraw()){
			v->draw(r,screen,updatecache);
		}
	}
	bool MainMenuLayout::confirmdraw(){return notified|redraw;}
}